﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;

namespace CoursePack
{
    public static class Tools
    {

        public static string DaysToDays(List<DayOfWeek> _Days)
        {
            string tmp = "-------";
            foreach (DayOfWeek d in _Days)
            {
                switch (d)
                {
                    case DayOfWeek.Monday:
                        tmp = ReplacePos(tmp,"M",0,1);
                        break;
                    case DayOfWeek.Tuesday:
                        tmp = ReplacePos(tmp, "T", 1, 1);
                        break;
                    case DayOfWeek.Wednesday:
                        tmp = ReplacePos(tmp, "W", 2, 1);
                        break;
                    case DayOfWeek.Thursday:
                        tmp = ReplacePos(tmp, "J", 3, 1);
                        break;
                    case DayOfWeek.Friday:
                        tmp = ReplacePos(tmp, "F", 4, 1);
                        break;
                    case DayOfWeek.Saturday:
                        tmp = ReplacePos(tmp, "S", 5, 1);
                        break;
                    case DayOfWeek.Sunday:
                        tmp = ReplacePos(tmp, "D", 6, 1);
                        break;
                }
            }

            return tmp;
        }

        public static string ReplacePos(string _str, string _add, int _pos, int _length)
        {
            var theString = _str;
            var aStringBuilder = new StringBuilder(theString);
            aStringBuilder.Remove(_pos, _length);
            aStringBuilder.Insert(_pos, _add);

            return aStringBuilder.ToString();
        }

        public static string[] filterCourse(string _course)
        {
            string CourseName = "";
            string CourseNumber = "";

            foreach (char c in _course)
            {
                if (char.IsDigit(c))
                {
                    CourseNumber += c;
                }
                else if (char.IsLetter(c))
                    CourseName += c;
            }

            return new string[2] { CourseName, CourseNumber };
        }

        public static float ParseCredits(string _Credits)
        {

            string result = "";
            try
            {
                Regex regexObj = new Regex(@"\d+\.?\d?\d?");
                result = regexObj.Match(_Credits).Value;
            }
            catch
            {

            }
            return float.Parse(result);
        }
    }
}
